var {getLoginedUser, fnLoading, fnHideLoading, fnSuccess, fnFail} = require('../../utils/index')
import {get} from "../../utils/request.js";
import {checkLoginAsyc} from "../../utils/util.js";
const app = getApp()

Page({
    bindGetUserInfo(e) {
        let that = this;
        app.authSetting(e)
            .then(user => {
                that.onLoad();
            })
            .catch(e => {
            })
    },
    datas() {
        wx.navigateTo({
            url: '../my-update/index',
        })
    },
    /**
     * 页面的初始数据
     */
    data: {
        name: "",
        menus: [
            {
                id: 1,
                label: '我的订单',
                icon: '/image/swiper/12.png',
                url: '../order-from/index'
            },
          {
            id: 10,
            label: '我的申请',
            icon: '/image/swiper/12.png',
            url: '../my-service/index'
          },
            {
                id: 2,
                label: '知识产权交易',
                icon: '/image/swiper/13.png',
                url: '../knowledge/index'
            },
            {
                id: 3,
                label: '我的通知',
                icon: '/image/swiper/14.png',
                url: '../Partner/index'
            },
            {
                id: 4,
                label: '合伙人推广',
                icon: '/image/swiper/15.png',
                //url: '../popularize/index?id=' + that.data.id + "&headimgurl=" + that.data.imgurl,
            },
            {
                id: 5,
                label: '我的佣金',
                icon: '/image/swiper/16.png',
                url: '../commission/index'
            }
        ],
        tel: "",
        num: "1",
        profile: "",//用户简介
        info: {},
        infos: true,
        imgurl: "",//用户头像
        id: ""
    },

    // 跳转到植物卡页面
    kapian(e){
        wx.navigateTo({
            url: e.currentTarget.dataset.url
        })
    },
    onShow(){
        this.onLoad(this.data.options || {})
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        let that = this;
      wx.hideTabBar();
      app.customTabBar()
        get({
            path: "/user/getInfo"
        }).then(function (res) {
            that.setData({
                loginBgFlag: false,
                phone: res.user.phone,
                name: res.user.nickName,
                profile: res.user.profile || '您还有设置简介哦～',
                imgurl: res.user.headimgurl,
                id: res.user.id,
                menus:[
                    ...that.data.menus.slice(0,4),
                    Object.assign({},that.data.menus[4],{
                      url: '../popularize/index?id=' + 
                      res.user.id + "&headimgurl=" + res.user.headimgurl
                }),
                    ...that.data.menus.slice(5),
                ]
            })

        }).catch(function (err) {
            checkLoginAsyc();
            console.log(err);
        })

    },

})
